﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
using Torrenter.Common.Objects;
using Torrenter.Manager.Services;

namespace Torrentter.UI.client.ViewModel
{
    public class SearchTorrentsViewModel : ViewModelBase
    {

        #region public properties

        public RelayCommand SearchCommand { get; set; }

        public string SearchString { get { return _SearchString; } set { _SearchString = value; RaisePropertyChanged("SearchString"); } }
        private string _SearchString;

        public int SeasonNumber { get { return _SeasonNumber; } set { _SeasonNumber = value; RaisePropertyChanged("SeasonNumber"); } }
        private int _SeasonNumber;

        public bool AllSeason { get { return _AllSeason; } set { _AllSeason = value; RaisePropertyChanged("AllSeason"); } }
        private bool _AllSeason;

        public int FromEpisode { get { return _FromEpisode; } set { _FromEpisode = value; RaisePropertyChanged("FromEpisode"); } }
        private int _FromEpisode;

        public int ToEpisode { get { return _ToEpisode; } set { _ToEpisode = value; RaisePropertyChanged("ToEpisode"); } }
        private int _ToEpisode;

        #endregion // public properties

        public SearchTorrentsViewModel()
        {
            SearchCommand = new RelayCommand(OnSearch);
            FromEpisode = 1;
            ToEpisode = 24;
        }        

        private void OnSearch()
        {

            if (string.IsNullOrWhiteSpace(SearchString))
            {
                return;
            }

            //if (this.SeasonNumber != 0 && (this.FromEpisode == 0 || this.ToEpisode == 0))
            //{
                //search a full season
                var s =  ShowSeason.GenerateSeason(SearchString,SeasonNumber,FromEpisode,ToEpisode);
                var addedTorrents = TorrentManager.Instance.AddTorrent(s);
                //Messenger.Default.Send<TorrentsAddedMsg>(new TorrentsAddedMsg() {ShowSeason = addedTorrents});
            //}
        }
    }
}
